23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 bool boom(int m
, int n
, int x0
, int y0
, int x1
, int y1
, int p
, int q
) {
28 if (p
== 0 or q
== 0) {
29 int c
= p
* (y1
- y0
) - q
* (x1
- x0
);
32 x0
*= abs(q
), x1
*= abs(q
), m
*= abs(q
);
33 y0
*= abs(p
), y1
*= abs(p
), n
*= abs(p
);
37 int d1
= p
* (y1
- y0
) - q
* (x1
- x0
);
38 int d2
= p
* (2*n
- y1
- y0
) - q
* (x1
- x0
);
39 int d3
= p
* (y1
- y0
) - q
* (2*m
- x1
- x0
);
40 int d4
= p
* (2*n
- y1
- y0
) - q
* (2*m
- x1
- x0
);
42 int g
= __gcd(2*n
*q
, 2*m
*p
);
44 if (d1
% g
== 0) return true;
45 if (d2
% g
== 0) return true;
46 if (d3
% g
== 0) return true;
47 if (d4
% g
== 0) return true;
52 int m
, n
, x0
, y0
, x1
, y1
, p
, q
;
53 while (cin
>> m
>> n
>> x0
>> y0
>> x1
>> y1
>> p
>> q
) {
54 if (m
== 0 and n
== 0 and x0
== 0 and y0
== 0 and x1
== 0 and y1
== 0 and p
== 0 and q
== 0) break;
55 if (boom(m
, n
, x0
, y0
, x1
, y1
, p
, q
)) {